<template>
  <div class="bankAdd">
    <div>
      <el-button type="primary" size="mini" @click="save">{{ $t('btn.save') }}</el-button>
    </div>
    <el-form :model="proValue" size="mini" label-width="100px">
      <!--      <el-form-item label="创建组织">-->
      <!--        <el-select v-model.trim="proValue.fcreateorgid">-->
      <!--          <el-option-->
      <!--            v-for="option in teamList"-->
      <!--            :key="option.fid"-->
      <!--            :label="option.fname"-->
      <!--            :value="option.fid"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="使用组织">-->
      <!--        <el-select v-model.trim="proValue.fuseorgid">-->
      <!--          <el-option-->
      <!--            v-for="option in teamList"-->
      <!--            :key="option.fid"-->
      <!--            :label="option.fname"-->
      <!--            :value="option.fid"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item :label="$t('menu.cashAccount')">
        <el-input v-model="proValue.fcashaccount" />
      </el-form-item>
      <el-form-item :label="$t('market.accountname1')">
        <el-input v-model="proValue.faccountname" />
      </el-form-item>
      <el-form-item :label="$t('market.defaultUser')">
        <el-input v-model.trim="proValue.fdefaultusername">
          <i
            slot="suffix"
            class="el-input__icon el-icon-search"
            @click="departRenVisiblit=true"
          />
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('market.note')">
        <el-input v-model="proValue.fremark" />
      </el-form-item>
    </el-form>
    <!--员工-->
    <responRen v-if="departRenVisiblit" @depart="departData1" />
  </div>
</template>

<script>
import bility from '@/mixin/Operability'
import { insertCashAccount } from '@/api/financial/teller'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'

export default {
  name: 'CashAccountAdd',
  components: {
    responRen: () => import('@/views/quality/qualityDetail/component/responRen')
  },
  mixins: [autocomplete, bility],
  data() {
    return {
      departRenVisiblit: false,
      proValue: {
        fcreateorgid: 1,
        fuseorgid: 1,
        fdefaultusername: '',
        fdefaultuserid: '',
        faccountname: '',
        fcashaccount: '',
        fremark: ''
      }
    }
  },
  methods: {
    // 保存
    save() {
      insertCashAccount(this.proValue).then(res => {
        if (res.code === 0) {
          // 关闭当前页面
          this.$store.dispatch('tagsView/guanbi', this.$route)
          this.$router.push({ path: `/cashAccountDetail/${res.data.fbankaccountId}` })
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 用户
    departData1(ev) {
      if (ev.fuserId) {
        this.proValue.fdefaultusername = ev.fname
        this.proValue.fdefaultuserid = ev.fuserId
      }
      this.departRenVisiblit = false
    }
  }
}
</script>

<style scoped lang="scss">
.bankAdd {
  @include listBom;
  background: #fff;
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .el-form {
    margin-top: 5px;
    //display: flex;
    flex-wrap: wrap;
    .el-form-item {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 10px;
      .el-input {
        width: 180px;
      }
    }
  }
}
</style>

